<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">参数设置</h3>
    </div>
    <div class="panel-body" style="min-height: 400px">
        <div class="form-group">
            <label for="txt_companyname">公司名称</label>
            <input type="text" class="form-control" value="<?= empty($companyname)?"":$companyname["keyvalue"] ?>" id="txt_companyname">
        </div>
        <div class="form-group">
            <label for="txt_companyaddr">公司地址</label>
            <input type="text" class="form-control" value="<?= empty($companyaddr)?"":$companyaddr["keyvalue"] ?>" id="txt_companyaddr">
        </div>
        <div class="form-group">
            <label for="txt_companytel">联系电话</label>
            <input type="text" class="form-control" value="<?= empty($companytel)?"":$companytel["keyvalue"] ?>" id="txt_companytel">
        </div>
        <div class="form-group">
            <label for="txt_companyemail">公司邮箱</label>
            <input type="text" class="form-control" value="<?= empty($companyemail)?"":$companyemail["keyvalue"] ?>" id="txt_companyemail">
        </div>
        <div class="form-group">
            <label for="txt_companyperson">联系人</label>
            <input type="text" class="form-control" value="<?= empty($companyperson)?"":$companyperson["keyvalue"] ?>" id="companyperson">
        </div>
        <div class="form-group">
            <label>微信二维码(<a href="javascript:" class="uploadimage">上传图片</a> <a href="javascript:" class="clearimage">清空图片</a>)</label>
            <?= _include('@views/admin/upload-image.php', ['img_style' => "max-height:100px",'imgplace_style' => "height:100px;width:100px","img_url"=>empty($companyqrcode)?"":$companyqrcode["keyvalue"]]); ?>
        </div>
        <button type="button" class="btn btn-primary btn-save">保存</button>
    </div>
</div>

<script>
    $(function(){
        $(".btn-save").on("click",function(){
            var data_list=[];
            $("input").each(function(){
                var $this=$(this);
                var value=$.trim($(this).val());
                if(value!=""){
                    data_list.push({
                        "keyname":$this.attr("id").replace("txt_",""),
                        "keyvalue":value
                    });
                }
            });
            data_list.push({
                "keyname":"companyqrcode",
                "keyvalue":$.trim($("#img-url").attr("src"))
            });

            $.ajax({
                type: "post",
                url: "/admin/save-company",
                data: "data_list="+MyJson.toString(data_list),
                beforeSend: function () {
                    $(".btn-save").val("保存中").attr("disabled","disabled");
                },
                success: function(msg){
                    $(".btn-save").val("保存").removeAttr("disabled");
                    toastr.success( "保存成功");
                    window.location.href=window.location.href;
                },
                error:function(){
                    $(".btn-save").val("保存").removeAttr("disabled");
                    toastr.error( "保存失败");
                    window.location.href=window.location.href;
                }
            });
        });
    })
</script>